home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
eventq.exe
/
SCRDEMO.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-07-13
|
14KB
|
380 lines
{****************************************************************************}
{ This unit demonstrates a method by which one can automate a Turbo Vision }
{ application using the event queue defined in EVENTQ.PAS. It declares a }
{ a descendant of TEventQApp which, in addition to functioning as a near- }
{ equivalent of TApplication, also has the ability to read keystrokes out of }
{ a script file. In order to run the demo, you need to make a copy of }
{ TVDEMO.PAS and make the following changes: }
{ }
{ 1) Add 'ScrDemo' to the 'uses' statement. }
{ 2) Change all occurrences of 'TApplication' to 'TScriptApp' (5 total). }
{ }
{ After making the changes, compile the modified copy of TVDEMO to disk and }
{ run it from the command line. Be sure that SCRIPT.SCR and SCRDEMO.PAS are }
{ both present in the current directory before you run the demo. }
{ }
{ This unit is intended to be a demo only. You will probably need to make }
{ changes, unless the only thing you want to do is animate a Turbo Vision }
{ program (as a self-running demo, for example). See SCRIPT.SCR for details }
{ on the syntax of the script language. }
{****************************************************************************}
{$X+}
unit ScrDemo;
interface
uses Dos,Drivers,Objects,MsgBox,EventQ;
{****************************************************************************}
{ The name of the script file is hard-coded as shown below. For a real }
{ application, you will probably want to make it a parameter passed to Init. }
{****************************************************************************}
const
ScriptFileName: PathStr = ('SCRIPT.SCR');
type
PScript = ^TScript;
TScript = object (TObject)
F: Text;
FileIsOpen: Boolean;
constructor Init (FileName: PathStr);
procedure Run (P: PEventQApp);
destructor Done; virtual;
end;
PScriptApp = ^TScriptApp;
TScriptApp = object (TEventQApp)
Scr: TScript;
constructor Init;
procedure Idle; virtual;
destructor Done; virtual;
end;
implementation
const
WaitTime: LongInt = (0);
DefaultWaitTime: LongInt = (0);
WaitStart: LongInt = (0);
Waiting: Boolean = (False);
{****************************************************************************}
{ ScanCodes is an array which correlates the ASCII characters with the }
{ keyboard scan codes that would have been generated, had the characters }
{ really come from the keyboard. In some cases, more than one scan code will }
{ result in the same character; in such cases, one of the possible scan }
{ codes was arbitrarily chosed for this array. }
{****************************************************************************}
ScanCodes: array[#0..#255] of Byte = (
$79,$1E,$30,$2E,$20,$12,$21,$22,$23,$17,$24,$25,$26,$32,$31,$18,
$19,$10,$13,$1F,$14,$16,$2F,$11,$2D,$15,$2C,$1A,$2B,$1B,$07,$0C,
$39,$02,$28,$04,$05,$06,$08,$28,$0A,$0B,$09,$0D,$33,$0C,$34,$35,
$0B,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$27,$27,$33,$0D,$34,$35,
$03,$1E,$30,$2E,$20,$12,$21,$22,$23,$17,$24,$25,$26,$32,$31,$18,
$19,$10,$13,$1F,$14,$16,$2F,$11,$2D,$15,$2C,$1A,$2B,$1B,$07,$0C,
$29,$1E,$30,$2E,$20,$12,$21,$22,$23,$17,$24,$25,$26,$32,$31,$18,
$19,$10,$13,$1F,$14,$16,$2F,$11,$2D,$15,$2C,$1A,$2B,$1B,$29,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00);
function StripSpaces (S: String): String;
begin
while S[1] = ' ' do Delete (S,1,1);
while S[Length (S)] = ' ' do Delete (S,Length (S),1);
StripSpaces := S;
end;
function Upper (S: String): String;
var
I: Integer;
begin
for I := 1 to Length (S) do S[I] := UpCase (S[I]);
Upper := S;
end; {Upper}
{****************************************************************************}
{ The huge TranslateKey procedure converts key commands in the script file }
{ into the equivalent Turbo Vision events. }
{****************************************************************************}
procedure TranslateKey (S: String; var Event: TEvent);
var
Value,ErrCode: Integer;
begin
Event.What := evKeyDown;
if Length (S) = 1 then
begin
Event.CharCode := S[1];
Event.ScanCode := ScanCodes[S[1]];
end
else if S[1] = '^' then
begin
if S[1] = '@' then
begin
Event.CharCode := #0;
Event.ScanCode := ScanCodes[#0];
end
else if S[1] in ['A'..'_'] then
begin
Event.CharCode := Char (Byte (S[1]) - Byte ('A'));
Event.ScanCode := ScanCodes[Char (Byte (S[1]) - Byte ('A'))];
end
else if S[1] in ['a'..'z'] then
begin
Event.CharCode := Char (Byte (S[1]) - Byte ('a'));
Event.ScanCode := ScanCodes[Char (Byte (S[1]) - Byte ('a'))];
end
else Event.What := evNothing;
end
else if S[1] = '#' then
begin
Delete (S,1,1);
Val (S,Value,ErrCode);
if (ErrCode = 0) and (Value >= 0) and (Value <= 255) then
begin
Event.CharCode := Char (Value);
Event.ScanCode := ScanCodes[Event.CharCode];
end
else Event.What := evNothing;
end
else if (S[1] in ['K','k']) and (S[2] in ['B','b']) then
begin
Delete (S,1,2);
S := Upper (S);
if S = 'ALTA' then Event.KeyCode := $1E00
else if S = 'ALTB' then Event.KeyCode := $3000
else if S = 'ALTC' then Event.KeyCode := $2E00
else if S = 'ALTD' then Event.KeyCode := $2000
else if S = 'ALTE' then Event.KeyCode := $1200
else if S = 'ALTF' then Event.KeyCode := $2100
else if S = 'ALTG' then Event.KeyCode := $2200
else if S = 'ALTH' then Event.KeyCode := $2300
else if S = 'ALTI' then Event.KeyCode := $1700
else if S = 'ALTJ' then Event.KeyCode := $2400
else if S = 'ALTK' then Event.KeyCode := $2500
else if S = 'ALTL' then Event.KeyCode := $2600
else if S = 'ALTM' then Event.KeyCode := $3200
else if S = 'ALTN' then Event.KeyCode := $3100
else if S = 'ALTO' then Event.KeyCode := $1800
else if S = 'ALTP' then Event.KeyCode := $1900
else if S = 'ALTQ' then Event.KeyCode := $1000
else if S = 'ALTR' then Event.KeyCode := $1300
else if S = 'ALTS' then Event.KeyCode := $1F00
else if S = 'ALTT' then Event.KeyCode := $1400
else if S = 'ALTU' then Event.KeyCode := $1600
else if S = 'ALTV' then Event.KeyCode := $2F00
else if S = 'ALTW' then Event.KeyCode := $1100
else if S = 'ALTX' then Event.KeyCode := $2D00
else if S = 'ALTY' then Event.KeyCode := $1500
else if S = 'ALTZ' then Event.KeyCode := $2C00
else if S = 'ALT1' then Event.KeyCode := $7800
else if S = 'ALT2' then Event.KeyCode := $7900
else if S = 'ALT3' then Event.KeyCode := $7A00
else if S = 'ALT4' then Event.KeyCode := $7B00
else if S = 'ALT5' then Event.KeyCode := $7C00
else if S = 'ALT6' then Event.KeyCode := $7D00
else if S = 'ALT7' then Event.KeyCode := $7E00
else if S = 'ALT8' then Event.KeyCode := $7F00
else if S = 'ALT9' then Event.KeyCode := $8000
else if S = 'ALT0' then Event.KeyCode := $8100
else if S = 'F1' then Event.KeyCode := $3B00
else if S = 'F2' then Event.KeyCode := $3C00
else if S = 'F3' then Event.KeyCode := $3D00
else if S = 'F4' then Event.KeyCode := $3E00
else if S = 'F5' then Event.KeyCode := $3F00
else if S = 'F6' t